package strategy;

import strategy.browser.BFSTreeBrowser;
import strategy.browser.BrowseStrategyEnum;
import strategy.browser.DFSTreeBrowser;
import strategy.browser.TreeBrowser;

public class TreePrinter {

	private TreeBrowser treeBrowser;
	private Node.INodeAction nodePrinter;

	public TreePrinter(BrowseStrategyEnum strategy) {
		setStrategy(strategy);
		nodePrinter = new Node.INodeAction() {
			@Override
			public void doAction(Node node) {
				System.out.print("(" + node.getIdDFS() + "," + node.getIdBFS() + ")");
			}
		};
	}

	public void setStrategy(BrowseStrategyEnum strategy) {
		switch (strategy) {
		case BFS:
			treeBrowser = new BFSTreeBrowser();
			break;
		case DFS:
			treeBrowser = new DFSTreeBrowser();
			break;
		}
	}

	public void printTree(Node root) {
		treeBrowser.browse(root, nodePrinter);
	}
}
